package org.springsocial.app;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springsource.model.Task;
import org.springsource.model.User;

/**
 * Handles requests for the application home page.
 */
@Controller
public class HomeController {
	
	private static final Logger logger = LoggerFactory.getLogger(HomeController.class);
	@RequestMapping(value = "/api/v1/tasks", produces = "application/json",method=RequestMethod.GET)
    @ResponseBody
	public List<Task> list() {
		logger.info("in response body ");
		List<Task> tasks = new ArrayList<Task>(3);
		for (int i = 0; i < 3; i++) {
			Task t = new Task();
			t.setDescription("asas");
			t.setDone(true);
			t.setId((long) i);
			tasks.add(t);
		}
        return tasks;
    }
	@RequestMapping(value = "/isonline", produces = "application/json",method=RequestMethod.GET)
    @ResponseBody
	public Map<String,Boolean> isOnline() {
		logger.info("in adasha ");
		Map<String,Boolean> isOnline = new HashMap<String,Boolean>(1);
		isOnline.put("onLine", true);
		return isOnline;
    }
	
	@RequestMapping(value = "/user",method=RequestMethod.POST,consumes={"application/*"})
    @ResponseBody
	public User postUser(@RequestBody User user) {
		logger.info("postUser ",user.toString());
		return user;
    }
	
	@RequestMapping(value = "/user/{name}.*",method=RequestMethod.GET)
    @ResponseBody
	public User gettUser(@PathVariable String name) {
		logger.info("name ",name);
		User user = new User();
		user.setUsername(name);
		return user;
    }
	
	@RequestMapping(value = "/user/{name}",method=RequestMethod.GET)
    @ResponseBody
	public User getUser(@PathVariable String name) {
		logger.info("name ",name);
		User user = new User();
		user.setUsername(name);
		return user;
    }
	
	
}
